<template>
  <div class="shoppingcart-conten">
    <header class="cart-head">
      <i class="iconfont icon-fanhui" @click="$router.go(-1)"></i>
      <h3>
        购物车<span v-if="cateList.length > 0">({{ cateList.length }})</span>
      </h3>
      <div class="edit" @click="editShow = !editShow">
        {{ editShow ? "完成" : "编辑" }}
      </div>
    </header>

    <div class="cart-main" v-if="cateList.length !== 0">
      <div class="cart-main-warp">
        <div v-for="(goods, i) in cateList" :key="i" class="goods-item">
          <CartGoodsItem :goods="goods" :condition="true"></CartGoodsItem>
        </div>
      </div>
      <GoodsSubmitBar :editShow="editShow"></GoodsSubmitBar>
    </div>
    <!-- 购物车为空时 -->
    <div class="gouwc" v-else>
      <img src="@/assets/image/cartgouwcimg.png" alt="" />
      <div class="gouwc-info">
        <p>你的购物车空空如也</p>
        <div class="btn" @click="$router.push('/home')"><p>去逛逛</p></div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapMutations, mapState } from "vuex";
import CartGoodsItem from "@/components/CartGoodsItem.vue";
import GoodsSubmitBar from "@/components/GoodsSubmitBar.vue";
export default {
  components: {
    CartGoodsItem,
    GoodsSubmitBar,
  },
  data() {
    return {
      editShow: false, //编辑or完成
    };
  },
  methods: {},
  computed: {
    ...mapState("m_cart", ["cateList"]),
  },
  mounted() {
    document
      .querySelector("body")
      .setAttribute("style", " background-color: #f6f6f6");
  },
  beforeDestroy() {
    document.body.removeAttribute("style");
  },
};
</script>

<style lang="scss" scoped>
.shoppingcart-conten {
}
.cart-head {
  position: fixed;
  top: 0;
  display: flex;
  height: 45px;
  line-height: 45px;
  justify-content: space-between;
  width: 100%;
  z-index: 999;
  background-color: #fff;
  border: 1px solid rgb(218, 215, 215);
  .icon-fanhui,
  h3,
  .edit {
    color: #5e5e5e;
  }
  .icon-fanhui {
    flex: 0 0 45px;
    font-size: 20px;
    text-align: center;
  }
  h3 {
    font-size: 18px;
  }
  .edit {
    flex: 0 0 45px;
    font-size: 12px;
  }
}
.cart-main {
  margin: 45px 0;
  padding: 10px 10px 0 10px;

  .cart-main-warp {
    // background-color: #fff;
    .goods-item {
      margin-top: 10px;
    }
    padding-bottom: 30px;
  }
}
.gouwc {
  width: 100%;
  position: relative;
  img {
    width: 100%;
  }
  .gouwc-info {
    position: absolute;
    bottom: 20px;
    left: 50%;
    text-align: center;
    transform: translate(-50%);
    > p {
      font-size: 12px;
      color: #5e5e5e;
    }
    .btn {
      color: white;
      line-height: 20px;
      background: #ff5777;
      box-sizing: border-box;
      font-size: 15px;
      padding: 6px 12.5px;
      border-radius: 4px;
      vertical-align: middle;
      margin: 6px 6px;
      cursor: pointer;
      user-select: none;
      min-width: 100px;
      text-align: center;
    }
  }
}
</style>